package hit.reports;

import static org.junit.Assert.*;

import java.io.File;
import java.util.Iterator;

import hit.core.Barcode;

import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

public class BuilderTest {

	@Test
	public void TestTitle() {
		
		TestBuilder builder = new TestBuilder();
		
		builder.setTitle("MyTitle");
		assertEquals("Initial title not returned correctly", builder.getTitle(), "MyTitle");
		
		builder.setTitle("OtherTitle");
		assertEquals("New title not returned correctly", builder.getTitle(), "OtherTitle");
	}
	
	
	@Test
	public void TestParagraphs()
	{
		BuilderParagraph para1 = new BuilderParagraph();
		assertEquals("Initial title not set to empty string.", para1.getValue(), "");
		
		BuilderParagraph para2 = new BuilderParagraph("This is my new Paragraph.");
		assertEquals("Initial title not set to value.", para2.getValue(), "This is my new Paragraph.");
		
		para1.setValue("MyValue");
		assertEquals("Updated value not returned correctly.", para1.getValue(), "MyValue");
		
		try
		{
			para1.setValue(null);
			fail("Should have thrown exception");
		}
		catch (IllegalArgumentException ex)
		{
		}
	}
	
	@Test
	public void TestHeaders()
	{
		BuilderHeader head1 = new BuilderHeader();
		assertEquals("Initial title not set to empty string.", head1.getValue(), "");
		
		BuilderHeader head2 = new BuilderHeader("This is my new Header.");
		assertEquals("Initial title not set to value.", head2.getValue(), "This is my new Header.");
		
		head1.setValue("A Header");
		assertEquals("Updated value not returned correctly.", head1.getValue(), "A Header");
		
		try
		{
			head1.setValue(null);
			fail("Should have thrown exception");
		}
		catch (IllegalArgumentException ex)
		{
		}
	}
	
	@Test
	public void TestOrdering()
	{
		TestBuilder builder = new TestBuilder();
		BuilderObject[] objects = new BuilderObject[3];
		
		objects[0] = new BuilderHeader("MyHeader");
		builder.AddObject(objects[0]);
		
		objects[1] = new BuilderParagraph("MyParagraph");
		builder.AddObject(objects[1]);
		
		objects[2] = new BuilderTable();
		builder.AddObject(objects[2]);
		
		Iterator<BuilderObject> iter = builder.GetObjectsIterator();
		
		for (int i = 0; iter.hasNext(); i++)
		{
			assertEquals("Index " + i + " was not in the correct order.", objects[i], iter.next()); 
		}
	}
}
